package com.apes.hr.base.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.frame.model.Branch;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * 功能：人员调动记录
 * @author Linwz
 * @create 2019-02-26 09:51
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = TransferRecord.CONST_TABLE_NAME)
public class TransferRecord extends Model {
    public static final String CONST_TABLE_NAME = "hr_Transfer_Record";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "人员调动记录")
    @Comment("编码")
    private long id; //编码

    @ManyToOne
    @JoinColumn(name = "employee_id", referencedColumnName = "id", nullable = false)
    @Comment("员工")
    private Employee employee; //员工

    @ManyToOne
    @JoinColumn(name = "work_branch_id", referencedColumnName = "id")
    @Comment("工作部门")
    private Branch workBranch; //工作部门

    @ManyToOne
    @JoinColumn(name = "post_id", referencedColumnName = "id")
    @Comment("岗位")
    private WorkPost post; //岗位

    @ManyToOne
    @JoinColumn(name = "job_id", referencedColumnName = "id")
    @Comment("职位")
    private Job job; //职位


    @ManyToOne
    @JoinColumn(name = "rank_id", referencedColumnName = "id")
    @Comment("职级")
    private Rank rank; //职级

    @ManyToOne
    @JoinColumn(name = "on_duty_state", referencedColumnName = "id")
    @Comment("在职状态")
    private Enumeration onDutyState; //在职状态(onDutyState)

    @Column(name = "driver",  nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否准驾人员")
    private boolean driver = false; // 是否准驾人员(0:否;1:是)

    @Column(name = "echelon", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否梯队")
    private boolean echelon = false;  //是否梯队(0:否;1:是)

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "transfer_on")
    @Comment("调至日期")
    private Date transferOn;//调至日期

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "transfer_out")
    @Comment("调离日期")
    private Date transferOut;//调离日期


    @Column(name = "transfer_application_item_id")
    @Comment("调动单明细号")
    private String transferApplicationItemId;//调动单明细号

    @Column(name = "old_Item_id")
    @Comment("调动单明细号")
    private String oldTransferApplicationItemId;//前一张调动单明细号

    @Column(name = "Apply_JobOrder_Id")
    @Comment("入职单号")
    private  String ApplyJobOrderId; // 入职单号

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    private boolean valid = true; //有效
}
